package usually;

import java.util.Arrays;

//567. 字符串的排列
public class Num567_checkInclusion {
    public boolean checkInclusion(String s1, String s2) {
        int n1 = s1.length();
        int n2 = s2.length();
        if (n1 > n2)return false;
        int l = 0 ;
        int r = n1 - 1;
        while (r < n2) {
            if (isAnagram(s2.substring(l , r + 1) , s1)){
                return true;
            }
            l++;
            r++;
        }
        return false;


    }

    public boolean isAnagram(String s, String t) {
        if (s.length() != t.length())return false;
        int arrs[] = new int[26];
        int arrt[] = new int[26];
        for (int i = 0; i < s.length(); i++) {
            arrs[s.charAt(i) - 'a']++;
            arrt[t.charAt(i) - 'a']++;
        }
        return Arrays.equals(arrs,arrt);
    }

}
